package com.anoopsoft

class Patron {

	String username
	String postCode
	String emailAddress
	/** **/
	String lang

	//'lang' will be injected with the locale so that Custom Validation can be made possible
	static transients = ['lang']

	static constraints = {
		username(blank:false,length:5..15, unique:true)
		postCode(blank:false)
		lang(blank:false)
		emailAddress(blank:false, email:true, validator:{val, obj ->
			
			println "lang is " + obj?.lang + "val is $val"
			if(obj?.lang?.startsWith("en") && (val?.endsWith(".org.uk") || val?.endsWith("co.uk") || val?.endsWith(".biz")))
			{
				println "English checking"
				return true
			}

			else if(obj?.lang?.equalsIgnoreCase("pt_BR") &&  (val?.endsWith("org.br") || val?.endsWith(".info")))
			{
				println "Portugeese checking"
				return true
			}

			else if( obj?.lang?.startsWith("es") &&  (val?.endsWith(".miapuesta-es") || val?.endsWith(".vistabet")))
				{
					println "Spanish checking"
					return true
				}
				else {
					println "Domain Chks. failed"
					return "notpermitted.email.domains.custom.msg";
				}
			})
	}
}